﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cqrs.Infrastructure.Database;
using Cqrs.Infrastructure;
using Ninject;
using Cqrs.StateMachineDesigner.Database;

namespace Cqrs.StateMachineDesigner.CustomCode
{
    internal class NinjectBinder : Ninject.Modules.NinjectModule
    {
        //public static string RavenDbLocation { get; set; }

        private static StandardKernel _kernel;
        public static StandardKernel NinjectKernel
        {
            get
            {
                if (_kernel == null)
                    throw new InvalidOperationException("The EventStore has not been configured");
                return _kernel;
            }
        }

        static NinjectBinder()
        {
            if (_kernel == null)
                _kernel = new StandardKernel(new NinjectBinder());
        }


        public override void Load()
        {
            if (string.IsNullOrEmpty(DesignerCanvas.DbLocation))
                throw new InvalidOperationException("The Raven Db Location has not been set");
            Bind<IEventStore>()
                .To<EventStore.RavenDb>()
                .WithConstructorArgument("dbPath", DesignerCanvas.DbLocation)
                .WithConstructorArgument("createDbFolder", false);
            Bind<IEventPublisher>().To<EventPublisher>();
        }
    }
}
